package com.itheima.entry.service.impl;

import com.itheima.entry.dao.IStudentDAO;
import com.itheima.entry.dao.IUserDao;
import com.itheima.entry.domain.UserInfo;
import com.itheima.entry.factory.StudentFactroy;
import com.itheima.entry.factory.UserFactroy;
import com.itheima.entry.service.IUserService;

import java.io.File;

public class UserServiceImpl implements IUserService {
    private IUserDao userDao = UserFactroy.getDao();
    private static IStudentDAO stuDao = StudentFactroy.getDao();


    @Override
    public boolean isUserExist(String username) {

        return userDao.isUserExist(username);
    }

    @Override
    public boolean isEmailExist(String email) {

        return userDao.isEmailExist(email);
    }

    @Override
    public boolean register(UserInfo user) {

        if (isUserExist(user.getUsername())) {
            return false;
        }
        return userDao.register(user);
    }

    @Override
    public boolean isAdmin(String key) {

        return userDao.isAdmin(key);
    }


    @Override
    public boolean login(String username, String password) {

        return userDao.login(username, password);
    }

    @Override
    public UserInfo getUser(String username) {
        return userDao.getUser(username);
    }


    @Override
    public String getLastDate(String username) {
        return null;
    }

    @Override
    public void ChangePassword(String username, String newPassword) {
        userDao.ChangePassword(username, newPassword);
    }

    //对密码的正确性进行判断
    @Override
    public boolean isCorrect(String username, String password) {
        return userDao.isCorrect(username, password);
    }

    @Override
    public boolean importInfo(File file) {
        return stuDao.importInfo(file);
    }

    @Override
    public boolean exportInfo(String username) {
        return stuDao.exportInfo(username);
    }

    @Override
    public String getSuperKey() {
        return userDao.getSuperKey();
    }

    @Override
    public boolean readLogs() {
        return false;
    }
}
